﻿
Namespace LightSwitchApplication

    Public Class SearchPayPeriods

        Private Sub CreateTimeSheetsMethod_Execute()
            ' Write your code here.
            If Not PayPeriods.SelectedItem Is Nothing Then
                Dim startPayPeriod = PayPeriods.SelectedItem.StartDate.[Date]
                While startPayPeriod <= PayPeriods.SelectedItem.EndDate.[Date]
                    For Each Employee As Employee In DataWorkspace.LightPayDatabase.Employees
                        Dim newTimeSheetEntry = Me.DataWorkspace.ApplicationData.TimeSheets.AddNew
                        With newTimeSheetEntry
                            .TimeSheetDate = startPayPeriod
                            .Employee = Employee
                            '.TimeStart = Nothing
                            '.TimeFinish = Nothing
                            .PayPeriod_Id = PayPeriods.SelectedItem.Id
                        End With
                        Me.DataWorkspace.ApplicationData.SaveChanges()
                    Next
                    startPayPeriod = startPayPeriod.AddDays(1)
                End While
            End If
        End Sub
    End Class

End Namespace
